﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel.Description;

namespace HeziService
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
            
        }
        private ServiceHost host = null;
        protected override void OnStart(string[] args)
        {
            host = new ServiceHost(typeof(HeziMsg),new Uri("http://localhost:8800/Hezi"));
            
            var http= host.AddServiceEndpoint(typeof(IHeziMsg), new WebHttpBinding(), "");
            http.EndpointBehaviors.Add(new WebHttpBehavior());
            if (host.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
            {
                ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
                behavior.HttpGetEnabled = true;
                behavior.HttpGetUrl = new Uri("http://localhost:8800/Hezi/metadata");
                host.Description.Behaviors.Add(behavior);
            }
            host.Open();
        }

        protected override void OnStop()
        {
            if (host != null || host.State != CommunicationState.Closed)
            {
                host.Close();
            }
        }
    }
}
